package com.yidu.logisticssystem.service.impl;

import com.yidu.logisticssystem.entity.LogisticsCardriver;
import com.yidu.logisticssystem.entity.LogisticsStaff;
import com.yidu.logisticssystem.dao.LogisticsStaffDao;
import com.yidu.logisticssystem.entity.vo.SiteStaffVo;
import com.yidu.logisticssystem.service.LogisticsStaffService;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 员工表(LogisticsStaff)表服务实现类
 *
 * @author makejava
 * @since 2021-03-08 16:46:55
 */
@Service("logisticsStaffService")
public class LogisticsStaffServiceImpl implements LogisticsStaffService {
    @Resource
    private LogisticsStaffDao logisticsStaffDao;

    /**
     * 通过ID查询单条数据
     *
     * @param staffId 主键
     * @return 实例对象
     */
    @Override
    public LogisticsStaff queryById(Integer staffId) {
        return this.logisticsStaffDao.queryById(staffId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<LogisticsStaff> queryAllByLimit(int offset, int limit) {
        return this.logisticsStaffDao.queryAllByLimit(offset, limit);
    }


    /**
     * 查询全部员工类数据
     * @param logisticsStaff
     * @return
     */
    @Override
    public List<LogisticsStaff> queryAll(LogisticsStaff logisticsStaff) {
        return this.logisticsStaffDao.queryAll(logisticsStaff);
    }

    /**
     * 新增数据
     *
     * @param logisticsStaff 实例对象
     * @return 实例对象
     */
    @Override
    public LogisticsStaff insert(LogisticsStaff logisticsStaff) {
        this.logisticsStaffDao.insert(logisticsStaff);
        return logisticsStaff;
    }

    /**
     * 修改数据
     *
     * @param logisticsStaff 实例对象
     * @return 实例对象
     */
    @Override
    public LogisticsStaff update(LogisticsStaff logisticsStaff) {
        this.logisticsStaffDao.update(logisticsStaff);
        return this.queryById(logisticsStaff.getStaffId());
    }

    @Override
    public int updateNull(Integer sectionId) {
        return logisticsStaffDao.updateNull(sectionId);
    }

    /**
     * 通过主键删除数据
     *
     * @param staffId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer staffId) {
        return this.logisticsStaffDao.deleteById(staffId) > 0;
    }

    /**
     * 批量删除
     * @param ids //字符串类型
     * @return
     */
    @Override
    public int deleteAll(String ids) {
        // 前台传过来的是一个数组 String [] id=ids.split(",")
        String [] id=ids.split(",");
        return this.logisticsStaffDao.deleteAll(id);
    }


    /**
     * 根据职位id查找所有司机姓名
     * @param postId
     * @return
     */
    @Override
    public List<LogisticsStaff> selectCarOutPeople(Integer postId) {
        return this.logisticsStaffDao.selectCarOutPeople(postId);
    }

    /**
     * 员工登录方法
     * @param logisticsStaff
     * @return
     */
    @Override
    public LogisticsStaff login(LogisticsStaff logisticsStaff) {
        return this.logisticsStaffDao.login(logisticsStaff);
    }

    @Override
    public List<LogisticsStaff> findAlls(LogisticsStaff staff) {
        return logisticsStaffDao.findAlls(staff);
    }

    /**
     * 查询全部
     * @return
     */
    @Override
    public List<LogisticsStaff> findAll() {
        return this.logisticsStaffDao.findAll();
    }

    @Override
    public List<LogisticsStaff> selectkdy(HttpServletRequest request) {
        LogisticsStaff staff = (LogisticsStaff)request.getSession().getAttribute("staff");

                String areaid=staff.getMapId(); //地区编号
        return logisticsStaffDao.selectkdy(areaid);
    }

    /**
     * 查询员工账号唯一
     * @param logisticsStaff
     * @return
     */
    @Override
    public LogisticsStaff queryByStaffName(LogisticsStaff logisticsStaff) {
        return this.logisticsStaffDao.queryByStaffName(logisticsStaff);
    }

    /**
     * 查询部门和职位
     * @param staffId
     * @return
     */
    @Override
    public LogisticsStaff select(Integer staffId) {
        return this.logisticsStaffDao.select(staffId);
    }

    /**
     * 根据员工类型查询员工姓名和员工编号
     * @param postId
     * @return
     */
    @Override
    public List<SiteStaffVo> queryByPostId(Integer postId) {


        return this.logisticsStaffDao.queryByPostId(postId);
    }

    @Override
    public List<SiteStaffVo> queryByStaffNum(String staffNum) {

        return this.logisticsStaffDao.queryByStaffNum(staffNum);
    }


    /**
     * 增加员工类数据
     * @param logisticsStaff
     * @return
     */
    @Override
    @Transactional
    public int insertSelective(LogisticsStaff logisticsStaff) {

        return this.logisticsStaffDao.insertSelective(logisticsStaff);


    }
    /**
     * 增加司机类数据
     * @param logisticsCardriver
     * @return
     */
    @Override
    public int insertSelective2(LogisticsCardriver logisticsCardriver) {
        return this.logisticsStaffDao.insertSelective2(logisticsCardriver);
    }

    /**
     * 修改员工类数据
     * @param logisticsStaff
     * @return
     */
    @Override
    public int updateByPrimaryKeySelective(LogisticsStaff logisticsStaff) {
        return this.logisticsStaffDao.updateByPrimaryKeySelective(logisticsStaff);
    }
}
